package lego.animal;

import java.util.ArrayList;

import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.util.Delay;

public abstract class IAnimal {

	protected String name = "";
	protected int burstSpeed = 80;
	protected int normalSpeed = 60;
	protected int stamina = 100;
	protected int staminaHighBound = 70;
	protected int staminaLowBound = 20;
	protected int life = 100;
	protected String sound[] = new String[4];
	
	// animal have lost, both prey and predator
	public String getLose()
	{
		return sound[3];
	}
	
	public void setLose(String s)
	{
		sound[3] = s;
	}
	
	// Predator have won
	// Prey is wandering around
	public String getWin()
	{
		return sound[2];
	}
	
	public void setWin(String s)
	{
		sound[2] = s;
	}
	
	//Predator has miss the attack
	// Prey have detected danger
	public String getMiss()
	{
		return sound[1];
	}
	
	public void setMiss(String s)
	{
		sound[1] = s;
	}
	
	// Predator have hit prey
	// Prey has been hit
	public String getHit()
	{
		return sound[0];
	}
	
	public void setHit(String s)
	{
		sound[0] = s;
	}
	
	public int getStaminaHighBound() {
		return staminaHighBound;
	}

	public void setStaminaHighBound(int staminaHighBound) {
		this.staminaHighBound = staminaHighBound;
	}

	public int getStaminaLowBound() {
		return staminaLowBound;
	}

	public void setStaminaLowBound(int staminaLowBound) {
		this.staminaLowBound = staminaLowBound;
	}
	
	public void setName(String n)
	{
		name = n;
	}
	
	public String getName()
	{
		return name;
	}
	
	public void setBurstSpeed(int speed)
	{
		burstSpeed = speed;
	}
	
	public int getBurstSpeed()
	{
		return burstSpeed;
	}
	
	public void setNomalSpeed(int speed)
	{
		normalSpeed = speed;
	}
	
	public int getNormalSpeed()
	{
		return normalSpeed;
	}
	
	public void setStamina(int stam)
	{
		if(stam < 100)
			stamina = stam;
		else
			stamina = 100;
	}
	
	public int getStamina()
	{
		return stamina;
	}
	
	public void setLife(int life)
	{
		if(life < 100)
			this.life = life;
		else
			this.life = 100;
	}
	
	public int getLife()
	{
		return life;
	}
	
	public static IAnimal selectAnimal(ArrayList<IAnimal> animals)
	{
		LCD.drawString("Select an animal", 0, 0);
		
		for(int i = 0; i < animals.size(); i++)
		{
			LCD.drawString(animals.get(i).getName(), 2, i+1);
		}
		
		LCD.drawChar('>', 0, 1);
		
		int chose = 1;
		while(Button.ENTER.isUp())
		{
			if(Button.LEFT.isDown())
			{
				LCD.drawChar(' ', 0, chose);
				chose = decreasChose(chose, animals.size());
				LCD.drawChar('>', 0, chose);
				Delay.msDelay(300);
			}
			
			else if(Button.RIGHT.isDown())
			{
				LCD.drawChar(' ', 0, chose);
				chose = increasChose(chose, animals.size());
				LCD.drawChar('>', 0, chose);
				Delay.msDelay(300);
			}
			else if(Button.ESCAPE.isDown())
			{
				//LCD.drawString("Extiting", 0, 7);
				System.exit(1);
			}
			
			Delay.msDelay(100);
			//while(Button.RIGHT.isDown() | Button.LEFT.isDown()){}
		}
		
		return animals.get(chose-1);
	}
	
	private static int decreasChose(int c, int numAnimals)
	{
		if(c == 1)
			c = numAnimals;
		else
			c--;
		return c;
	}
	
	private static int increasChose(int c, int numAnimals)
	{
		if(c == numAnimals)
			c = 1;
		else
			c++;
		return c;
	}
}
